#coding=utf-8
'''
Created on 2018年6月8日

@author: Administrator
'''
import itertools

def comb(collection, m):
    return _comb([], collection, m)

def _comb(head, tail, m):
    if m == 1:
        return [ head + [elem] for elem in tail]
    elif m == len(tail):
        return [head + tail]
    else:
        r1 = _comb([tail[0]], tail[1:], m - 1)
        r11 = [head + elem for elem in r1]
        r2 = _comb([], tail[1:], m)
        r21 = [head + elem for elem in r2]
        return r11 + r21
        

result = comb([1,2,3,4,5],3)
print "comb(5,3) has {} results".format(len(result))
print result

aa = [i for i in range(10)]


print comb(aa, 5) 
print list(itertools.combinations(aa, 5))
    